version 17
set more off
quietly log
local logon = r(status)
	if "`logon'" == "on"  {
	log close	
	}
log using analysis_support_for_a_strong_leader_or_democracy, text replace

/*******************************************************************************
	Project   : Support for a strong leader or democracy, or both?
	File Name : analysis_support_for_a_strong_leader_or_democracy.do
	Date	  : Jan 25th, 2024 (Latest update)
	Purpose	  : Conducting the analysis that is included in the paper.
		
	Input	  : 1) Data_support_for_a_strong_leader_or_democracy.dta - Final Data set
				   			
	Output	  : 1) analysis_support_for_a_strong_leader_or_democracy.log       - Log File
					
******************************************************************************  */

**# 1. Calling the final data set
	use "data/Data_support_for_a_strong_leader_or_democracy.dta", clear
	
	*Rescaling the variables
	generate log_gdppc_wb_lag = log(cnt_gdppc_wb_lag)
	generate log_cnt_all_mig_prop_lag = log(cnt_all_mig_prop_lag)
	label variable log_gdppc_wb_lag "Log(GDP per capita (Lag))"
	label variable log_cnt_all_mig_prop_lag "Log(Migration (%) (Lag))"
	
	summarize dem_auto_four econ_anxiety culture_conserv_2 conf_parli conf_party conf_gov ///
			  age male educ_three married employed poli_interest income_tenth_mid right_ideology_mid social_trust ///
			  cnt_all_mig_prop_lag cnt_gdppc_wb_lag cnt_unemployment_wb_lag gini_disp_mean_lag cnt_libdem_vdem_lag
			  
	mdesc dem_auto_four econ_anxiety culture_conserv_2 conf_parli conf_party conf_gov ///
			  age male educ_three married employed poli_interest income_tenth_mid right_ideology_mid social_trust ///
			  cnt_all_mig_prop_lag cnt_gdppc_wb_lag cnt_unemployment_wb_lag gini_disp_mean_lag cnt_libdem_vdem_lag
	
	unique country_year
	unique country_name
	tabulate country_name, gen(country_dummy)
	
**# 2. Distribution of different supporter types across countries
	bysort wave: tab country_name dem_auto_four, row
	
	preserve
	contract wave dem_auto_four, zero freq(freq)
	bysort wave: egen total = total(freq)
	
	gen prop_dem = freq/ total if dem_auto_four==0
	gen prop_auto= freq/ total if dem_auto_four==1
	gen prop_guar= freq/ total if dem_auto_four==2
	gen prop_pess= freq/ total if dem_auto_four==3
	
	graph twoway (connected prop_dem wave) ///
				 (connected prop_auto wave) ///
				 (connected prop_guar wave) ///
				 (connected prop_pess wave), xlabel(3 "1994-1998" 4 "1999-2004" 5 "2005-2009" 6 "2010-2014" 7 "2017-2020", angle(45) labsize(small))  ///
											 legend(on size(small) ///
												order(1 "Democracy supporters" ///
													  2 "Authoritarianism supporters" ///
													  3 "Guardianship democracy supporters" ///
													  4 "Political pessimists")) saving(global_distribution, replace)
	restore
	
	preserve 
	contract wave country_name dem_auto_four, zero freq(freq)
	
	gen sample =0
	replace sample=1 if country_name == "Argentina"  |country_name == "Australia"    |country_name == "Bangladesh" |country_name == "Belarus"   |country_name == "Bolivia"   |country_name == "Bosnia and Herzegovina"|country_name == "Brazil" ///
					    |country_name == "Bulgaria"  |country_name == "Burkina Faso" |country_name == "Canada"     |country_name == "Chile"     |country_name == "Cyprus"    |country_name == "Czech Republic"        |country_name == "Ecuador" ///
					    |country_name == "Estonia"   |country_name == "Finland"      |country_name == "France"     |country_name == "Georgia"   |country_name == "Germany"   |country_name == "Ghana"                 |country_name == "Greece" ///
					    |country_name == "Guatemala" |country_name == "Hungary"      |country_name == "Colombia"   |country_name == "India"     |country_name == "Indonesia" |country_name == "Italy"                 |country_name == "Japan" ///
						|country_name == "Latvia"    |country_name == "Lebanon"      |country_name == "Libya"      |country_name == "Lithuania" |country_name == "Mali"      |country_name == "Mexico" 
	
	sort country_name wave dem_auto_four
	
	drop if dem_auto_four==.
	
	bysort country_name wave: egen total = total(freq)
	
	gen prop_dem = freq/ total if dem_auto_four==0
	gen prop_auto= freq/ total if dem_auto_four==1
	gen prop_guar= freq/ total if dem_auto_four==2
	gen prop_pess= freq/ total if dem_auto_four==3
	
	
	graph twoway (connected prop_dem wave) ///
				 (connected prop_auto wave) ///
				 (connected prop_guar wave) ///
				 (connected prop_pess wave) if sample == 1, by(country_name) saving(country_distribution1, replace)
	
	graph twoway (connected prop_dem wave) ///
				 (connected prop_auto wave) ///
				 (connected prop_guar wave) ///
				 (connected prop_pess wave) if sample == 0, by(country_name) saving(country_distribution2, replace)
				 
	restore

**# 3. Descriptive Analysis
	bysort dem_auto_four:corr conf_parli conf_party conf_gov
	
	bysort dem_auto_four: summarize  dem_essential_obeyrule dem_essential_better dem_importance dem_essential_liberty
	
		tabulate  dem_auto_four dem_essential_obeyrule, chi2
		tabulate  dem_auto_four dem_importance, chi2
		tabulate  dem_auto_four dem_essential_better, chi2
		tabulate  dem_auto_four dem_essential_liberty, chi2
	
		* Anova for econ and cultural anxieties (continuous)
		anova econ_anxiety dem_auto_four
		anova culture_conserv_2 dem_auto_four
		
		* Chi-square test for confidence in institutions
		tabulate dem_auto_four conf_parli, row chi2
		tabulate dem_auto_four conf_party, row chi2
		tabulate dem_auto_four conf_gov, row chi2
		
		*VIF check
		reg dem_auto_four econ_anxiety culture_conserv_2 conf_parli conf_party conf_gov ///
							   age male educ_three married employed poli_interest income_tenth_mid right_ideology_mid social_trust ///
							   log_cnt_all_mig_prop_lag log_gdppc_wb_lag cnt_unemployment_wb_lag gini_disp_mean_lag cnt_libdem_vdem_lag
							   
		reg dem_auto_four conf_parli conf_party conf_gov 
							   
		vif // Mean VIF = 1.6
		
		ktau conf_parli conf_party, stats(p taub) // Kendall's tau-b = 0.6212 (Significant)
		ktau conf_parli conf_gov, stats(p taub)   // Kendall's tau-b = 0.5932 (Significant)
		ktau conf_party conf_gov, stats(p taub)   // Kendall's tau-b = 0.5167 (Significant)

								
**# 4. Multinomial logit Analysis

	gsem 	(dem_auto_four <-  econ_anxiety culture_conserv_2 conf_parli conf_party conf_gov ///
							   age male educ_three married employed poli_interest income_tenth_mid right_ideology_mid social_trust ///
							   log_cnt_all_mig_prop_lag log_gdppc_wb_lag cnt_unemployment_wb_lag gini_disp_mean_lag cnt_libdem_vdem_lag ///
							   M1[country_name] M2[country_name>country_year]) [pweight=equal_weight], cov(M1[country_name]*M2[country_name>country_year]@0) mlogit
	
	est store m1
	
**# 5. Predictive probability
	*First difference
	est restore m1
	margins, at(culture_conserv_2=(-1.98 -0.98 0.02) (median) _all) vsquish
	margins, at(conf_parli=(1 2 3 4) (median) _all) vsquish
	margins, at(conf_party=(1 2 3 4) (median) _all) vsquish
	margins, at(conf_gov=(1 2 3 4) (median) _all) vsquish
	
	margins, dydx(econ_anxiety culture_conserv_2 conf_parli conf_party conf_gov) at((median) _all) vsquish
	
**# 6. Robust check
	* Fixed effect + Cluster standard errors
	mlogit dem_auto_four econ_anxiety culture_conserv_2 conf_parli conf_party conf_gov ///
							   age male educ_three married employed poli_interest income_tenth_mid right_ideology_mid social_trust ///
							   log_cnt_all_mig_prop_lag log_gdppc_wb_lag cnt_unemployment_wb_lag gini_disp_mean_lag cnt_libdem_vdem_lag ///
							   i.country_dummy* i.year [pweight=equal_weight], vce(cluster country_year)

	* Different operationalization of DV
	gsem 	(robust_dem_auto_four <-  econ_anxiety culture_conserv_2 conf_parli conf_party conf_gov ///
							   age male educ_three married employed poli_interest income_tenth_mid right_ideology_mid social_trust ///
							   log_cnt_all_mig_prop_lag log_gdppc_wb_lag cnt_unemployment_wb_lag gini_disp_mean_lag cnt_libdem_vdem_lag ///
							   M1[country_name] M2[country_name>country_year]) [pweight=equal_weight], cov(M1[country_name]*M2[country_name>country_year]@0) mlogit	
	
log close
clear